﻿@using DCMS.Web.Extensions;
@using DCMS.Web.Framework;
@using DCMS.Web.Framework.UI;
@using DCMS.ViewModel.Models.Finances;
@using DCMS.ViewModel.Models.WareHouses;
@using System.Collections.Generic;
@using System.Linq;
@using DCMS.Core.Domain.Common;


@model CostPriceSummeryListModel


<section id="content_wrapper">

    <!-- Start: Topbar-Dropdown -->
    <div id="topbar-dropmenu">
        @await Html.PartialAsync("_ToolBox")
    </div>
    <!-- End: Topbar-Dropdown -->
    <!-- Start: Topbar -->
    <header id="topbar">
        <div class="topbar-left">
            <ol class="breadcrumb">
                <li class="crumb-active">
                    <a href="#">仓库</a>
                </li>
                <li class="crumb-icon">
                    <a href="@Url.RouteUrl("HomePage")">
                        <span class="glyphicon glyphicon-home"></span>
                    </a>
                </li>
                <li class="crumb-link">
                    <a href="#">库存报表</a>
                </li>
                <li class="crumb-trail">成本汇总表</li>
            </ol>
        </div>
        <div class="topbar-right">
            <div class="ml15 ib va-m" id="toggle_sidemenu_r">
                <a href="#" class="pl5">
                    <i class="fa fa-sign-in fs22 text-primary"></i>
                    <span class="badge badge-hero badge-danger">3</span>
                </a>
            </div>
        </div>
    </header>
    <!-- End: Topbar -->
    <!-- Begin: Content -->
    <section id="content" class="formSection">

        <div class="row">
            <div class="col-md-12">

                <form asp-action="CostPriceSummery" asp-controller="StockReport" method="get" id="formSearch" novalidate="novalidate">

                    <div class="panel panel-default" id="panel0">
                        <div class="panel-heading">
                            <span class="glyphicon glyphicon-search"></span> 高级搜索
                            <a class="btn btn-default btn-sm pull-right m5 mrn p5 pbn" id="AdvancedSearch"><i class="fa fa-angle-double-right"></i></a>
                        </div>
                        <div class="panel-body p10">

                            <div class="row">

                                <div class="col-sm-2">
                                    <dcms-select asp-for="RecordTime" asp-items="@Model.Dates" />
                                </div>

                                <div class="col-sm-2">
                                    <div class="input-group">

                                        <input asp-for="ProductId" type="hidden" />
                                        <input asp-for="ProductName" class="form-control" placeholder="商品名称..." />
                                        <span class="input-group-btn">
                                            <button id="btn_search_product" type="button" class="btn btn-default">
                                                <span class="glyphicon glyphicon-search"></span>
                                            </button>
                                        </span>
                                    </div>
                                </div>



                                <div class="col-sm-8">
                                    <button id="btn_query" type="submit" class="btn btn-primary btn-block">
                                        <span class="glyphicon glyphicon-search mr5" aria-hidden="true"></span>查询
                                    </button>
                                </div>

                            </div>
                        </div>
                    </div>

                </form>

                <div class="panel">
                    <div class="panel-heading">
                        <div class="panel-title">
                            <span class="glyphicon glyphicon-tasks"></span> 成本汇总
                        </div>
                    </div>
                    <div class="panel-body p10">

                        <div id="toolbar" class="btn-group mb10">
                            <a id="btn_export" class="btn btn-info btn-sm mr5">
                                <span class="glyphicon glyphicon-export mr5"></span>导出
                            </a>
                            <a href="@Url.Action("CostPriceSummery")" class="btn btn-default btn-sm mr5">
                                <span class="glyphicon glyphicon-refresh mr5"></span>重置
                            </a>

                        </div>



                        <table class="table table-striped table-bordered table-hover" id="datatable">
                            <tr>
                                <th class="w300 text-left" rowspan="2">商品编码</th>
                                <th class="text-left" rowspan="2">商品名称</th>
                                <th class="text-left" rowspan="2">单位</th>

                                <th class="text-center" colspan="3">期初</th>
                                <th class="text-center" colspan="3">收入</th>
                                <th class="text-center" colspan="3">支出</th>
                                <th class="text-center" colspan="3">期末结存</th>
                            </tr>
                            <tr>
                                <th class="text-right">数量</th>
                                <th class="text-right">成本单价</th>
                                <th class="text-right">成本金额</th>

                                <th class="text-right">数量</th>
                                <th class="text-right">成本单价</th>
                                <th class="text-right">成本金额</th>

                                <th class="text-right">数量</th>
                                <th class="text-right">成本单价</th>
                                <th class="text-right">成本金额</th>

                                <th class="text-right">数量</th>
                                <th class="text-right">成本单价</th>
                                <th class="text-right">成本金额</th>
                            </tr>

                            @{
                                if (Model.Items != null && Model.Items.Count > 0)
                                {
                                    @foreach (var item in Model.Items)
                                    {
                                        <tr>
                                            <td class="text-left">@item.ProductCode</td>
                                            <td class="text-left"><a href="@Url.Action("CostPriceChangeRecords","StockReport",new {startTime=Model.RecordTime,productId=@item.Id})" target="_blank">@item.ProductName</a></td>
                                            <td class="text-left">@item.UnitName</td>
                                            <td class="text-right">@item.InitQuantity</td>
                                            <td class="text-right">@item.InitPrice</td>
                                            <td class="text-right">@item.InitAmount</td>
                                            <td class="text-right">@item.InQuantity</td>
                                            <td class="text-right">@item.InPrice</td>
                                            <td class="text-right">@item.InAmount</td>
                                            <td class="text-right">@item.OutQuantity</td>
                                            <td class="text-right">@item.OutPrice</td>
                                            <td class="text-right">@item.OutAmount</td>
                                            <td class="text-right">@item.EndQuantity</td>
                                            <td class="text-right">@item.EndPrice</td>
                                            <td class="text-right">@item.EndAmount</td>

                                        </tr>
                                    }
                                    <!--//合计//-->
                                    <tr>
                                        <td colspan="3" class="text-right"><b>合计</b></td>
                                        <td class="text-right text-weight"><b>@((Model.Items.Select(s => s.InitQuantity).Sum()).ToString("#,##0.00"))</b></td>
                                        <td class="text-right text-weight"><b>@((Model.Items.Select(s => s.InPrice).Sum()).ToString("#,##0.00"))</b></td>
                                        <td class="text-right text-weight">￥ <b>@((Model.Items.Select(s => s.InitAmount).Sum()).ToString("#,##0.00"))</b></td>
                                        <td class="text-right text-weight"><b>@((Model.Items.Select(s => s.InQuantity).Sum()).ToString("#,##0.00"))</b></td>
                                        <td class="text-right text-weight"><b>@((Model.Items.Select(s => s.InPrice).Sum()).ToString("#,##0.00"))</b></td>
                                        <td class="text-right text-weight">￥ <b>@((Model.Items.Select(s => s.InAmount).Sum()).ToString("#,##0.00"))</b></td>
                                        <td class="text-right text-weight"><b>@((Model.Items.Select(s => s.OutQuantity).Sum()).ToString("#,##0.00"))</b></td>
                                        <td class="text-right text-weight"><b>@((Model.Items.Select(s => s.OutPrice).Sum()).ToString("#,##0.00"))</b></td>
                                        <td class="text-right text-weight">￥ <b>@((Model.Items.Select(s => s.OutAmount).Sum()).ToString("#,##0.00"))</b></td>
                                        <td class="text-right text-weight"><b>@((Model.Items.Select(s => s.EndQuantity).Sum()).ToString("#,##0.00"))</b></td>
                                        <td class="text-right text-weight"><b>@((Model.Items.Select(s => s.EndPrice).Sum()).ToString("#,##0.00"))</b></td>
                                        <td class="text-right text-weight">￥ <b>@((Model.Items.Select(s => s.EndAmount).Sum()).ToString("#,##0.00"))</b></td>
                                    </tr>
                                }
                                else
                                {
                                    <tr class="no-records-found"><td class="text-center" colspan="15">没有找到匹配的记录</td></tr>
                                }
                            }
                        </table>


                        @{
                            var pager = Html.Pager(Model.PagingFilteringContext).QueryParam("pagenumber");
                        }

                        @if (!pager.IsEmpty())
                        {
                            <div class="fixed-table-pagination" style="display: block;">
                                @Html.Raw(pager.ToString())
                            </div>
                        }

                    </div>
                </div>
            </div>
        </div>

    </section>

    <!-- End: Content -->
</section>



@await Html.PartialAsync("_Windows", Model)



@{
//Html.AddCssFileParts(ResourceLocation.Head, "~/assets/skin/default_skin/css/theme.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/Scripts/Toastr/toastr.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/Scripts/Tables/bootstrap-table.css");

//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/datepicker/css/bootstrap-datetimepicker.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/daterange/daterangepicker.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/colorpicker/css/bootstrap-colorpicker.min.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/tagmanager/tagmanager.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/fancytree/skin-win8/ui.fancytree.min.css");

//Html.AddCssFileParts(ResourceLocation.Head, "~/Content/Site.css");

}

@section CurPageScripts
{
    @{
//Html.AddScriptParts(ResourceLocation.Footer, "~/assets/js/utility/jquery.sparkline.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/jquery.validate.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/jquery.validate.unobtrusive.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Tables/jquery.treegrid.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Tables/bootstrap-table.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Tables/locale/bootstrap-table-zh-CN.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Tables/bootstrap-table-treegrid.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/globalize.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/moment.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/moment-with-locales.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/daterange/daterangepicker.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/datepicker/js/bootstrap-datetimepicker.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/colorpicker/js/bootstrap-colorpicker.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/jquerymask/jquery.maskedinput.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/tagmanager/tagmanager.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/fancytree/jquery.fancytree-all.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/assets/admin-tools/admin-forms/js/advanced/steps/jquery.steps.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Toastr/Toastr.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Custom/Common.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/assets/js/bootstrap/holder.min.js");
    }
    <script type="text/javascript">

        jQuery(document).ready(function () {

            "use strict";

            // Init Theme Core
            Core.init();

            // Init Demo JS
            Demo.init();

            //高级搜索
            $("#panel0 #AdvancedSearch").click(function () {
                var ico = $(this).find(".fa");
                if (ico.hasClass('fa-angle-double-right'))
                    ico.removeClass("fa-angle-double-right").addClass("fa-angle-double-down");
                else
                    ico.removeClass("fa-angle-double-down").addClass("fa-angle-double-right");
                $("#panel0").find(".panel-body").toggleClass("hidden fadeIn");
            });

            //商品列表选择赋值
            window.operateEventsPop = {
                'click .rowSelect': function (e, value, row, index) {
                    var index = $(this).attr("data-id");
                    var keys = Object.keys(row.Units);
                    $("#ProductName").val(row.Name);
                    $("#ProductId").val(row.Id);
                    $('#ModalProductWindows').modal('hide');
                }
            };
            $("#btn_search_product").click(function () {
                $(this).productSelectShowModal($("#ModalProductWindows"), "/Product/AsyncSearchSelectPopup", null, "选择商品", $("#ProductModalForm"),
                    function () { });
            });

            //防止重复查询
            var queryNumber = 1;
            $("#btn_query").click(function () {
                if (queryNumber > 1) {
                    return false;
                }
                queryNumber = queryNumber + 1;
            });

            //用户修改商品名称，将商品Id置零
            $("#ProductName").bind("change", function () {
                $("#ProductId").val(0);
            });

            //导出
            $("#btn_export").click(function () {
                window.location.href = "/StockReport/ExportCostPriceSummery?productId=" + $("#ProductId").val() + "&productName=" + $("#ProductName").val() + "&RecordTime=" + $("#RecordTime").val();
            });
        });
    </script>
}
